<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:output method="html" indent="no"/>

	<!-- 
		Root - SiteAudits
	-->
	<xsl:template match="/">
		<table cellpadding="2">
			<xsl:apply-templates select="SiteAudits/SiteAudit"/>
		</table>
	</xsl:template>

	<!-- 
		SiteAudit 
	-->
	<xsl:template match="SiteAudit">
		<xsl:if test="position()=1">
			<!-- Show column headers if this is the first site audit -->
			<tr class="ms-toolbar">
				<td valign="bottom">
					<font class="ms-globallinks">Site</font>
				</td>
				<td valign="bottom">
					<font class="ms-globallinks">Audit</font>
				</td>
				<xsl:apply-templates select="RuleInfo"/>
				<td valign="bottom">
					<font class="ms-globallinks">
						# Deficiencies
					</font>
				</td>
			</tr>
		</xsl:if>
		<xsl:apply-templates select="AuditResult">
			<xsl:with-param name="SiteTitle">
				<xsl:value-of select="@SiteTitle"/>
			</xsl:with-param>
			<xsl:with-param name="SiteType">
				<xsl:value-of select="@SiteType"/>
			</xsl:with-param>
			<xsl:with-param name="SiteUrl">
				<xsl:value-of select="@SiteUrl"/>
			</xsl:with-param>
		</xsl:apply-templates>
	</xsl:template>

	<!--
		RuleInfo
	-->
	<xsl:template match="RuleInfo">
		<td valign="bottom" width="32">
			<font class="ms-globallinks">
				<div title="{@RuleType}">
					<xsl:value-of select="@RuleName"/>
				</div>
			</font>
		</td>
	</xsl:template>

	<!-- 
		AuditResults
	-->
	<xsl:template match="AuditResult">
		<xsl:param name="SiteType"/>
		<xsl:param name="SiteTitle"/>
		<xsl:param name="SiteUrl"/>
		<tr>
			<!-- Show site information if this is the first audit result for this site -->
			<xsl:if test="position()=1">
				<td>
					<b>
						<a href="{$SiteUrl}">
							<xsl:value-of select="$SiteTitle"/>
						</a>
					</b>
					<br/>
					<xsl:value-of select="$SiteType"/>
				</td>
			</xsl:if>
			<xsl:if test="position()>1">
				<td>
				</td>
			</xsl:if>
			<td valign="center">
				<div title="Auditor: {@Auditor}">
					<xsl:if test="@AuditTitle!=''">
						<xsl:value-of select="@AuditTitle"/>
					</xsl:if>
					<xsl:if test="@AuditTitle=''">
						Audit # <xsl:value-of select="@AuditNumber"/>
					</xsl:if>
					<br/>
					<font color="gray">
						<xsl:value-of select="@AuditDate"/>
					</font>
				</div>
			</td>
			<xsl:if test="count(RuleResult)>0">
				<xsl:apply-templates select="RuleResult"/>
				<!-- Display number of deficiencies -->
				<td valign="center" align="center">
					<xsl:value-of select="count(RuleResult[@RuleResult='Noncompliant'])"/>
				</td>
			</xsl:if>
			<xsl:if test="count(RuleResult)=0">
				<td colspan="20">
					<i>
						(This audit was not specified)<br/>
						<br/>
					</i>
				</td>
			</xsl:if>
		</tr>
	</xsl:template>

	<!-- 
		RuleResult
	-->
	<xsl:template match="RuleResult">
		<td valign="center" align="center">
			<xsl:if test="@RuleResult ='Compliant'">
				<xsl:if test="@CompliantItemUrl!=''">
					<xsl:element name="a">
						<xsl:attribute name="href">
							<xsl:value-of select="@CompliantItemUrl"/>
						</xsl:attribute>
						<xsl:call-template name="CompliantImageTag"/>
					</xsl:element>
				</xsl:if>
				<xsl:if test="@CompliantItemUrl=''">
					<xsl:call-template name="CompliantImageTag"/>
				</xsl:if>
			</xsl:if>
			<xsl:if test="@RuleResult='Noncompliant'">
				<xsl:call-template name="ResultImageTag">
					<xsl:with-param name="resultname">Noncompliant</xsl:with-param>
					<xsl:with-param name="gifurl">_layouts/images/ewr215l.gif</xsl:with-param>
				</xsl:call-template>
			</xsl:if>
			<xsl:if test="@RuleResult='Untested'">
				<xsl:call-template name="ResultImageTag">
					<xsl:with-param name="resultname">Untested</xsl:with-param>
					<xsl:with-param name="gifurl">_layouts/images/ewr216l.gif</xsl:with-param>
				</xsl:call-template>
			</xsl:if>
			<xsl:if test="@RuleResult='Unknown'">
				<xsl:call-template name="ResultImageTag">
					<xsl:with-param name="resultname">Unknown</xsl:with-param>
					<xsl:with-param name="gifurl">_layouts/images/ewr219l.gif</xsl:with-param>
				</xsl:call-template>
			</xsl:if>
			<xsl:if test="@RuleResult ='NotApplicable'">
				<xsl:if test="@AuditComments!=''">
					<div title="{@AuditComments}">
						<font color="gray">n/a</font>
					</div>
				</xsl:if>
				<xsl:if test="@AuditComments=''">
					<div title="This rule doesn't apply to this audit.">
						<font color="gray">n/a</font>
					</div>
				</xsl:if>
			</xsl:if>
		</td>
	</xsl:template>

	<!-- 
		Utilities
	-->
	<!-- Render an image tag for Result = Compliant. -->
	<xsl:template name="CompliantImageTag">
		<xsl:element name="img">
			<xsl:attribute name="src">_layouts/images/ewr209l.gif</xsl:attribute>
			<xsl:if test="@CompliantItemName!=''">
				<xsl:attribute name="alt">
					<xsl:text>Compliant [</xsl:text>
					<xsl:value-of select="@CompliantItemName"/>
					<xsl:text>]</xsl:text>
				</xsl:attribute>
			</xsl:if>
			<xsl:if test="@CompliantItemName=''">
				<xsl:attribute name="alt">Compliant</xsl:attribute>
			</xsl:if>
			<xsl:attribute name="border">0</xsl:attribute>
		</xsl:element>
	</xsl:template>

	<!-- Render an image tag for other results. -->
	<xsl:template name="ResultImageTag">
		<xsl:param name="resultname"/>
		<xsl:param name="gifurl"/>
		<xsl:if test="@AuditComments!=''">
			<img src="{$gifurl}" alt="{$resultname}.  {@AuditComments}"/>
		</xsl:if>
		<xsl:if test="@AuditComments=''">
			<img src="{$gifurl}" alt="{$resultname}"/>
		</xsl:if>
	</xsl:template>

</xsl:stylesheet>